package com.warmlight.voicepacket.dbmanager;

import android.app.Activity;
import android.content.Context;

import com.warmlight.voicepacket.dao.DBFloatPlaylistDao;
import com.warmlight.voicepacket.dbdata.DBFloatPlaylist;

import org.greenrobot.greendao.query.WhereCondition;

import java.util.List;

public class DBFloatPlayListDaoHelp {

    public static void insert(Context context,DBFloatPlaylist dbFloatPlaylist){
        DBManager.getDaoSession(context).getDBFloatPlaylistDao().insert(dbFloatPlaylist);
    }

    public static void update(Activity aThis, DBFloatPlaylist data) {
        DBManager.getDaoSession(aThis).getDBFloatPlaylistDao().update(data);
    }

    public static List<DBFloatPlaylist> loadAll(Context context) {
        return DBManager.getDaoSession(context).getDBFloatPlaylistDao().loadAll();
    }

    public static List<DBFloatPlaylist> queryBuilder(Context aThis, WhereCondition eq) {
        return DBManager.getDaoSession(aThis).getDBFloatPlaylistDao().queryBuilder().where(eq)
                .list();

    }

    public static DBFloatPlaylist queryBuilderById(Context aThis, String ID) {

        return DBManager.getDaoSession(aThis).getDBFloatPlaylistDao().queryBuilder().where(DBFloatPlaylistDao.Properties.Id.eq(ID)).unique();
    }

    public static void deleteById(Activity aThis, Long id) {
        DBManager.getDaoSession(aThis).getDBFloatPlaylistDao().deleteByKey(id);
    }

    public static void deleteAudioId(Context context,String id){
        DBFloatPlaylist dbFloatPlaylist = queryBuilderById(context, id);
        dbFloatPlaylist.setList_audio("");
        dbFloatPlaylist.setList_count("0");
        update((Activity) context,dbFloatPlaylist);
    }

}
